package com.eugene.ui.provider;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;

import com.eugene.entity.Scenario;
import com.eugene.ui.Activator;



public class ScenarioLabel extends LabelProvider {
	private Map<ImageDescriptor,Image> imageCache = new HashMap<ImageDescriptor,Image>();
	private Image image;
	private List<ILabelProviderListener> listeners = new ArrayList<ILabelProviderListener>();
//	private List listeners = new ArrayList();
//	private static final Image sceSetImage; 
//		= Activator.getImageDescriptor("icons/showcat_co.gif").createImage();
//	private static final Image sceImage; 
//		= Activator.getImageDescriptor("icons/showdesc_co.gif").createImage();
	
	@Override
	public String getText(Object element) {
		if (element instanceof Scenario) {
			Scenario sce = (Scenario) element;
//			System.out.println("ccc-"+sce.getSceId());
			return sce.getSceId();
		}
		return element.toString();
	}
	
	@Override
	public Image getImage(Object element) {
		ImageDescriptor  imgDesc = null;

		if (element instanceof Scenario) {
			imgDesc =Activator.getImageDescriptor("icons/showcat_co.gif");
		}
		else imgDesc =Activator.getImageDescriptor("icons/showdesc_co.gif");
		
		if(!imageCache.containsKey(imgDesc)){
			image = imgDesc.createImage();
			imageCache.put(imgDesc,image);
		}
		
//		Image folderImg = PlatformUI.getWorkbench().getSharedImages()
//							.getImage(ISharedImages.IMG_OBJ_FOLDER);
//		imgDesc = AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.ui",
//							"$nl$/icons/full/etool16/import_wiz.gif");
		return imageCache.get(imgDesc);
	}
	@Override
	public void dispose(){
		for(Image img: imageCache.values()){
			img.dispose();
		}
		imageCache.clear();
	}

//	@Override
//	public void addListener(ILabelProviderListener listener) {
//	    listeners.add(listener);
//	}
//	@Override
//	public void removeListener(ILabelProviderListener listener) {
//	    listeners.remove(listener);
//	}
}
